package com.minishift.android.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 
 * this class is get device's network status.
 * @author Sirier
 *
 */
public class XNetworkStatus {

	public static final int STATUS_NO_NETWORK = 0; // no network
	public static final int STATUS_WIFI = 1; // WIFI
	public static final int STATUS_MOBILE = 2; // 2G or 3G

	/**
	 * this method will get current device's network status.
	 * @param Context: current Application
	 * @return int	0 no network,1	WIFI, 2	2G/3G
	 */
	public static int getNetworkStatus(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = manager.getActiveNetworkInfo();
		if (info != null && info.isConnected()) {
			if (NetworkInfo.State.CONNECTED == info.getState()) {
				switch (info.getType()) {
				case ConnectivityManager.TYPE_MOBILE:
					return STATUS_MOBILE;
				case ConnectivityManager.TYPE_WIFI:
					return STATUS_WIFI;
				default:
					return STATUS_NO_NETWORK;
				}
			} else {
				return STATUS_NO_NETWORK;
			}
		} else {
			return STATUS_NO_NETWORK;
		}
	}

}
